#include <stdio.h>
#include "ofc/DSimpleFont.h"

int main(int argc, char *argv[])
{
  DSimpleFont *font = [DSimpleFont new];
  DFT_Glyph    glyph;

  unsigned width,height;
                                       // Print font info
  printf("Family name:%s\n",    [font familyName]);
  printf("Style name:%s\n",     [font styleName]);
  printf("Glyphs in font:%d\n", [font glyphsInFont]);
  
  [font stringSize :"hello" :&width :&height]; // Get the string dimensions
  printf("String size of \"hello\":%u - %u\n", width, height);

  if ([font glyph :'a' :&glyph])       // Render the font to a glyph
  {
    unsigned xe = glyph.bitmapWidth -1;
    unsigned ye = glyph.bitmapHeight - 1;
    unsigned x,y;
    
    unsigned char *bitmap = glyph.bitmap;
   
    printf("Glyph bitmap:\n");         // Print the bitmap of the glyph
    for (y = 0; y <= ye; y++)
    {
      unsigned char  mask = 0x80;
      unsigned char *line = bitmap;
      
      for (x = 0; x <= xe; x++)
      {
        printf("%c", ((*line & mask) ? '1' : '0'));

        mask >>= 1;
        if (mask == 0)
        {
          mask = 0x80;
          line++;
        }
      }
      bitmap += glyph.bitmapPitch;
      printf("\n");
    }
  }
  else
    printf("The glyph 'a' is not present in the font.\n");

  [font free];

  return 0;
}

